<?php
defined('BASEPATH') or die('forbidden');
class Gangrole_Controller Extends Controller
{
	private $dbConnt;	//数据库连接
	private $signlist;	//签到标识
	private $joblist;	//职务列表
	private $nameList;
	private $issort;  //是否进行了公会成员的赠送排序(0:没有进行 1:有进行)
	
	function _init()
	{
		check_level(50,segment(0),segment(1));
		set_time_limit(0);
		
		//得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }
        $this->issort = array('0' => "没有进行", '1' => "有进行");
        
        // db数据库
		$this->dbConnt = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		
		if (false == $this->dbConnt) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
		$this->dbConnt->query('SELECT id, name FROM player');
		while ($n = $this->dbConnt->get_array('default'))
		{
			$this->nameList[$n['id']] = $n['name'];
		}
		$this->signlist = array('1'=>'未签到','0'=>'已签到');
		$this->joblist = array('0'=>'会长','1'=>'副会长','2'=>'精英','3'=>'普通');
	}

	function index()
	{
		$this->view->display("dbgang/gangrole/index");
	}
	function flexigrid()
	{
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			

		$sql = "SELECT COUNT(*) AS num FROM player_gang_role WHERE {$where} {$exwhere}";
		//echo " sql2:$sql ";
		$one = $this->dbConnt->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		 
		$sql = "SELECT {$colsinfo} FROM  player_gang_role WHERE {$where} {$exwhere} {$orderby} LIMIT {$offset},{$rp}";
		$this->dbConnt->query($sql);
		//$id = 0;
		while ($n = $this->dbConnt->get_array('default'))
		{
			$n['gang_sign']=$this->signlist[$n['gang_sign']]."-(".$n['gang_sign'].")";
			$n['job']=$this->joblist[$n['job']]."-(".$n['job'].")";
			$n['role_id'] = $this->nameList[$n['role_id']]."(".$n['role_id'].")";
			$n['issort'] = $this->issort[$n['issort']]."(".$n['issort'].")";
			$n['join_time']=get_datetime($n['join_time']);
			$n['last_sign_time']=get_datetime($n['last_sign_time']);
			date('Y', $n['hurttime']) == 1970 ? $n['hurttime'] = "" : $n['hurttime'] = date("Y-m-d h:m:s", $n['hurttime']);			
			$rows[] = array('id' => $n['gmid'], 'cell' => $n);
			//$id = $id+1;
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		$this->dbConnt->free_all();
		echo json_encode($result);
	}
	
	function del($id)
	{

	}
}
?>